(() => {
  let ele = {};
  ele.top_bl = $("#top_bl");
  ele.top_t1 = $("#top_t1");
  ele.top_t2 = $("#top_t2");
  ele.top_t3 = $("#top_t3");
  ele.top_br = $("#top_br");
  ele.top_t4 = $("#top_t4");
  ele.ferter = $("#ferter");
  ele.paihang = $("#paihang");
  ele.left_num = $("#left_num");
  ele.btn_fang = $("#btn_fang");
  ele.shang_top = $("#shang_top");
  ele.fanhui = $("#fanhui");
  ele.top_t_1 = $("#top_t_1");
  ele.top_t_2 = $("#top_t_2");
  ele.haohua = $("#haohua");
  ele.jinbidui = $("#jinbidui");
  ele.zuan = $("#zuan");
  ele.nengsd = $("#nengsd");
  ele.openinfo = $("#openinfo");
  ele.nengliang = $("#nengliang");
  ele.nengl = $("#nengl");
  ele.touxiang = $("#touxiang");
  ele.name_n = $("#name_n");
  ele.task = $("#task");
  ele.xingyun = $("#xingyun");
  ele.beibao = $("#beibao");
  ele.modal_transfer2 = $("#modal-transfer2");
  ele.duihuan = $("#duihuan");
  ele.modal_gold = $("#modal-gold");
  ele.goldRecord = $("#goldRecord");
  ele.close_gold = $("#close-gold");
  ele.jinbi3 = $("#jinbi3");
  ele.exchangeList = $("#exchangeList");
  ele.more1 = $("#more1");
  ele.list_today = $("#list-today");
  ele.more2 = $("#more2");
  ele.empty1 = $("#empty1");
  ele.exchange_confirm = $("#exchange-confirm");
  ele.ex_money = $("#ex_money");
  ele.ex_money2 = $("#ex_money2");
  ele.ex_gold = $("#ex_gold");
  ele.list_all = $("#list-all");
  ele.close_transfer2 = $("#close-transfer2");
  ele.exchangeList2 = $("#exchangeList2");
  ele.zuan_shi = $("#zuan_shi");
  ele.jinbi2 = $("#jinbi2");
  ele.zulouzheng = $("#zulouzheng");
  ele.juzhuzhneg = $("#juzhuzhneg");
  ele.fnagdongshu = $("#fnagdongshu");
  ele.option_all = $("#option-all");
  ele.transfer = $("#transfer");
  ele.modal_tips4 = $("#modal-tips4");
  ele.cuihui = $("#cuihui");
  ele.modal_info = $("#modal-info");
  ele.modal_give = $("#modal-give");
  ele.giveshouxu = $("#giveshouxu");
  ele.giveipt = $("#giveipt");
  ele.close_give = $("#close-give");
  ele.close_info = $("#close-info");
  ele.giveconsume = $("#giveconsume");
  ele.giveconfirm = $("#giveconfirm");
  ele.empty2 = $("#empty2");
  ele.modal_exchange = $("#modal-exchange");
  ele.modal_tips4 = $("#modal-tips4");
  ele.giveid = $("#giveid");
  ele.close_tips4 = $("#close-tips4");
  ele.infoname = $("#infoname");
  ele.infosex = $("#infosex");
  ele.infoid = $("#infoid");
  ele.infowx = $("#infowx");
  ele.copywx = $("#copywx");
  ele.liveFang = $("#liveFang");
  ele.infoqq = $("#infoqq");
  ele.copyqq = $("#copyqq");
  ele.headpic = $("#headpic");
  ele.infogroup = $("#infogroup");
  ele.infogroup2 = $("#infogroup2");
  ele.infotxt = $("#infotxt");
  ele.cardBox = $("#cardBox");
  ele.tanchuang = $("#tanchuang");
  ele.more4 = $("#more4");
  ele.empty4 = $("#empty4");
  ele.meiyou4 = $("#meiyou4");
  ele.jinduut = $("#jinduut");
  ele.jindul = $("#jindul");
  ele.jindus = $("#jindus");
  ele.nengliangjindu = $("#nengliangjindu");
  ele.prow_cjin = $("#prow_cjin");
  ele.btn_linprow = $("#btn_linprow");
  ele.close_exchange = $("#close-exchange");

  ele.modal_give2 = $("#modal-give2");
  ele.close_give2 = $("#close-give2");
  ele.jinbi4 = $("#jinbi4");
  ele.zhuan = $("#zhuan");
  ele.btn_linprow = $("#btn_linprow");
  ele.giveconfirm2 = $("#giveconfirm2");

  let list = [];
  let prowList = [];
  let obj = {};
  let page2 = 1;
  let page1 = 1;

  // 幸运数字
  ele.tips_number = $("#tips_number");
  ele.modal_number = $("#modal-number");
  ele.number_back = $("#number_back");
  ele.center_tijiao = $("#center_tijiao");
  ele.num_detlt_btn = $("#num_detlt_btn");
  ele.num_detlt_submit = $("#num_detlt_submit");
  ele.winning_record = $("#winning_record");
  ele.task_num = $("#task_num");
  ele.son_img = $("#son_img");
  ele.num_select = $("#num_select");
  ele.modal_species = $("#modal-species");
  ele.number3_img = $("#number3_img");
  ele.close_tips3 = $("#close-tips3");
  ele.number4_btn = $("#number4_btn");
  ele.modal_submitTo = $("#modal-submitTo");
  ele.modal_etails = $("#modal-details");
  ele.close_tips3 = $("#close-tips3");
  ele.son_num = $("#son_num");
  ele.num_text = $("#num_text");
  ele.close_details = $("#close_details");
  ele.modal_details = $("#modal-details");
  ele.numchance = $("#numchance");
  ele.djstext = $("#djstext");
  ele.yy_timer = $("#yy_timer");
  ele.wenhao = $("#wenhao");
  ele.now_cc = $("#now_cc");
  ele.last_cc = $("#last_cc");
  ele.close_shu2 = $("#close_shu2");
  ele.navcont_List = $("#navcont_List");
  ele.close_record = $("#close-record");
  ele.modal_record = $("#modal-record");
  ele.modal_prowcun = $("#modal-prowcun");
  ele.modal_shuomingtan = $("#modal-shuomingtan");
  
  ele.toplv = $('#toplv');
  
  ele.idin = $('#idin');
  
  let page = 1;
  // 幸运数字开始----------------
  // 打开幸运数子
  ele.tips_number.onclick = () => {
    getownnum();
    openMdl(ele.modal_number);
  };
	
	getUserInfo((res)=> {
		ele.paihang.style.display = res.no_ph == 1 ? 'none' : 'block'
	});
	
  // 关闭幸运数字
  ele.number_back.onclick = () => {
    // ele.modal_number.style.display = "none";
    closeMdl(ele.modal_number);
  };

  ele.son_img.onclick = () => {
    openMdl(ele.modal_etails);
    closeMdl(ele.modal_number);
  };

  // /关闭提交确认
  ele.number3_img.onclick = () => {
    closeMdl(ele.modal_submitTo);
  };
  // 关闭领取金币
  ele.close_tips3.onclick = () => {
    closeMdl(ele.modal_species);
  };
  // 点击打开能量记录
  ele.tanchuang.onclick = () => {
    nnegliangjl();
    openMdl(ele.modal_record);
  };
  // 关闭幸运数字说明
  ele.close_details.onclick = () => {
    closeMdl(ele.modal_details);
  };

  ele.num_detlt_btn.onclick = () => {
    closeMdl(ele.modal_details);
  };
  // 点击问好
  ele.wenhao.onclick = () => {
    openMdl(ele.modal_shuomingtan);
  };
  // 点击差
  ele.close_shu2.onclick = () => {
    closeMdl(ele.modal_shuomingtan);
  };
  // 打开能量存储
  ele.nengl.onclick = () => {
    openMdl(ele.modal_prowcun);
  };
  // 关闭能量存储
  ele.prow_cjin.onclick = () => {
    closeMdl(ele.modal_prowcun);
  };
  // 幸运数字结束----------------
  // todo点击跳转到交易中心
  ele.top_br.onclick = () => {
    location.href = "../page/fang_estate.html";
  };
  // todo点击矿山挖掘跳转到神秘矿山页面
  ele.top_bl.onclick = () => {
    // 刘欣 引导 挖矿 2023-6-22 19:04:04
    let ugid = guide.getUsersGuideId("userGuideId");
    if (~[134].indexOf(ugid)) guide.hideMine_150();
    location.href = "../page/mine2.html";
  };
  //关闭 转赠
  ele.close_give.onclick = () => {
    closeMdl(ele.modal_give);
  };
  //关闭 金币兑换
  ele.close_exchange.onclick = () => {
    closeMdl(ele.modal_exchange);
  };
  // todo点击按钮打开tabbar
  ele.btn_fang.onclick = () => {
    if (ele.shang_top.style.display == "block") {
      closeMdl(ele.shang_top);
      ele.shang_top.style.height = "0px";
    } else {
      ele.shang_top.style.height = "100px";
      openMdl(ele.shang_top);
    }
  };
  //打开 金币兑换
  ele.duihuan.onclick = () => {
    goldList();
    getBrickList(page2);
    getGoldList(page1);
    // openMdl(ele.modal_exchange);
  };
  //关闭 摧毁规则 交易规则
  ele.close_tips4.onclick = () => {
    closeMdl(ele.modal_tips4);
  };
  //关闭 金币兑换 兑换内容
  ele.close_transfer2.onclick = () => {
    closeMdl(ele.modal_transfer2);
  };
  // !关闭能量记录
  ele.close_record.onclick = () => {
    // todo清空数组
    prowList = [];
    page = 1;
    closeMdl(ele.modal_record);
  };
  //关闭 金币记录
  ele.close_gold.onclick = () => {
    closeMdl(ele.modal_gold);
  };
  // 点击跳转任务
  ele.task.onclick = () => {
    location.href = "../page/task.html";
  };
  //打开 金币记录
  ele.goldRecord.onclick = () => {
    openMdl(ele.modal_gold);
  };
  // !点击房东专属
  ele.fnagdongshu.onclick = () => {
    // openTips("敬请期待");
	location.href = '../page/luck.html'
  };
  ele.liveFang.onclick = () => {
    openTips("敬请期待");
	  // location.href = '../page/arena.html'
  };
  // !点击幸运数字
  // ele.xingyun.onclick = () => {
  //   openTips("敬请期待");
  // };
  //打开 玩家信息
  ele.openinfo.onclick = () => {
    let giveid = ele.giveid.value;
    if (!giveid) {
      openTips("请输入正确的好友ID");
    } else searchUser(giveid);
  };
  //关闭 玩家信息
  ele.close_info.onclick = () => {
    closeMdl(ele.modal_info);
  };

  // 点击跳转背包
  ele.beibao.onclick = () => {
    location.href = "../page/bag.html";
  };
  // todo点击返回隐藏
  ele.fanhui.onclick = () => {
    // closeMdl(ele.shang_top);
    // ele.shang_top.style.height = "0px";
    console.log(12151);
  };
  //打开 转赠
  ele.transfer.onclick = () => {
    toZs();
  };
  //打开 摧毁规则 交易规则
  ele.cuihui.onclick = () => {
    openMdl(ele.modal_tips4);
  };
  ele.top_t_1.onclick = (e) => {
    e.stopPropagation();
    console.log(111);
  };
  ele.top_t_2.onclick = (e) => {
    e.stopPropagation();
    console.log(111);
  };
  // 点击排行榜跳转到排行榜
  ele.paihang.onclick = () => {
    location.href = "../page/energy_Pai.html";
  };
  // 点击领取能量
  ele.btn_linprow.onclick = () => {
    lingprow();
  };
  asyncList();
  function asyncList() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.RUKOU,
      header: {
        Authorization: token,
      },
      success: (res) => {
        list = res.data.list;
        obj = res.data.detail;
        initList();
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }

  // 监听 转赠数量
  ele.giveipt.oninput = () => {
    // console.log(ele.giveipt.value);
    let num = ele.giveipt.value;
    let shouxufei = Math.floor(num * givesxf) / 100;
    ele.giveconsume.innerHTML = parseInt(num) + shouxufei;
  };
  // 转赠 确认
  ele.giveconfirm.onclick = () => {
    let giveid = ele.giveid.value;
    let givenum = ele.giveipt.value;
    zsDq(giveid, givenum);
  };
  // function zsDq(id, num) {
  //   let token = getCookie("token");
  //   ajax({
  //     url: API_PATH.ZS_DQ,
  //     method: "GET",
  //     header: {
  //       Authorization: token,
  //     },
  //     data: {
  //       code: id,
  //       num: num,
  //     },
  //     success: (res) => {
  //       if (res.code == 1) {
  //       } else openTips(res.msg || "未知错误");
  //     },
  //   });
  // }

  // 金币兑换列表
  function goldList() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.GOLD_LIST,
      method: "GET",
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.code == 1) {
          // openTips(res.msg);
          drawGoldList(res.data);
        } else openTips(res.msg || "未知错误");
      },
    });
  }
  //金币兑换 列表渲染
  function drawGoldList(_data) {
    let html = "";
    let html2 = "";
    let j = _data.length - 1;
    for (let i = 0; i < _data.length - 1; i++) {
      html +=
        '<div class="ex_ce_list">' +
        '<div class="ex_ce_list_top">' +
        '<div class="ex_ce_list_top1">' +
        '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/qb.png" alt="">' +
        "<span>￥" +
        _data[i].money +
        "</span>" +
        "</div>" +
        '<div class="ex_ce_list_top2">' +
        '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi.png" alt="">' +
        "<span>" +
        _data[i].gold +
        "</span>" +
        "</div>" +
        "</div>" +
        '<button class="ex_btn">兑换</button>' +
        "</div>";
    }
    html2 =
      '<div class="ex_price_in">' +
      '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/exchange/bg1.png" alt="">' +
      "<p>今日价格：￥" +
      _data[j].money +
      "</p>" +
      '<div class="ex_price_in2">' +
      '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi.png" alt="">' +
      "<span>" +
      _data[j].gold +
      "</span>" +
      "</div>" +
      "</div>" +
      '<button class="ex_btn ex_btn2">兑换</button>';
    ele.exchangeList.innerHTML = html;
    ele.exchangeList2.innerHTML = html2;

    openMdl(ele.modal_exchange);

    let ex_btns = $(".ex_btn");
    for (let i = 0; i < ex_btns.length; i++) {
      ex_btns[i].onclick = (e) => {
        // console.log(e.target.getAttribute('data'));
        // jobSynthesis(e.target.getAttribute('data'));
        ele.ex_money.innerHTML = _data[i].money + "大米";
        ele.ex_money2.innerHTML = _data[i].money;
        ele.ex_gold.innerHTML = _data[i].gold;
        openMdl(ele.modal_transfer2);
        exConfirm(_data[i].id);
      };
    }
  }

  // 确认兑换金币
  function exConfirm(id) {
    ele.exchange_confirm.onclick = () => {
      goldConfirm(id);
    };
  }

  // 确认兑换金币 接口
  function goldConfirm(id) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.GOLD_EXCHANGE,
      method: "POST",
      header: {
        Authorization: token,
      },
      data: {
        id: id,
      },
      success: (res) => {
        if (res.code == 1) {
          openTips(res.msg);
          // for (let i = 0; i < inval.length; i++) {
          // 	clearInterval(inval[i]);
          // }
          asyncList();
        } else openTips(res.msg || "未知错误");
      },
    });
  }
  // 金币记录
  function getBrickList(page) {
    ele.more1.innerText = "加载中...";
    let token = getCookie("token");
    ajax({
      url: API_PATH.GET_BRICK_LIST,
      method: "POST",
      header: {
        Authorization: token,
      },
      data: {
        page: page,
      },
      success: (res) => {
        if (res.code == 1) {
          let detail = res.data.data;
          if (detail.length === 0) {
            page = 0;
            ele.more2.style.display = "none";
            ele.empty2.style.display = "flex";
          } else {
            drawgetBrickList(detail);
            page2++;
            if (page2 > res.data.last_page) {
              ele.more2.innerText = "没有更多了";
              ele.more2.onclick = null;
            } else {
              ele.more2.innerText = "加载更多";
              ele.more2.onclick = () => getBrickList(page2);
            }
          }
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  // 金币记录渲染
  function drawgetBrickList(data) {
    if (data.length === 0) {
      page2 = 0;
      ele.more2.style.display = "none";
      ele.empty2.style.display = "flex";
    } else {
      let str = "";
      for (let i = 0; i < data.length; i++) {
        let resume = data[i].remark;
        let sign = data[i].operation_type == 1 ? "+" : "-";
        str +=
          '<div class="item">' +
          '	<div class="left">' +
          '		<div class="right">' +
          '			<p class="mobile">' +
          data[i].remark +
          "</p>" +
          '			<p class="time">' +
          data[i].created_at +
          "</p>" +
          "		</div>" +
          "	</div>" +
          '	<p class="amount">' +
          sign +
          data[i].money +
          "</p>" +
          "</div>";
      }
      ele.list_today.innerHTML += str;
    }
  }

  // 金币兑换
  function getGoldList(page) {
    ele.more1.innerText = "加载中...";
    let token = getCookie("token");
    ajax({
      url: API_PATH.GOLD_RECORD,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        page: page,
      },
      success: (res) => {
        if (res.code == 1) {
          let detail = res.data.list.data;
          if (detail.length === 0) {
            page1 = 0;
            ele.more1.style.display = "none";
            ele.empty1.style.display = "flex";
          } else {
            drawgetGoldList(detail);
            page1++;
            if (page1 > res.data.list.last_page) {
              ele.more1.innerText = "没有更多了";
              ele.more1.onclick = null;
            } else {
              ele.more1.innerText = "加载更多";
              ele.more1.onclick = () => getGoldList(page1);
            }
          }
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  // 金币兑换渲染
  function drawgetGoldList(data) {
    if (data.length === 0) {
      page1 = 0;
      ele.more1.style.display = "none";
      ele.empty1.style.display = "flex";
    } else {
      let str = "";
      for (let i = 0; i < data.length; i++) {
        let resume = data[i].remark;
        let sign = data[i].operation_type == 1 ? "+" : "-";
        str +=
          '<div class="item">' +
          '	<div class="left">' +
          '		<div class="right">' +
          '			<p class="mobile">' +
          resume +
          "</p>" +
          '			<p class="time">' +
          data[i].created_at +
          "</p>" +
          "		</div>" +
          "	</div>" +
          '	<p class="amount">' +
          sign +
          data[i].money +
          "</p>" +
          "</div>";
      }
      ele.list_all.innerHTML += str;
    }
  }

  // 转赠 确认
  ele.giveconfirm.onclick = () => {
    let giveid = ele.giveid.value;
    let givenum = ele.giveipt.value;
    ele.zhuan.innerHTML = "确认转赠" + givenum + "金币给" + giveid + "玩家吗？";
    openMdl(ele.modal_give2);

    // zsDq(giveid,givenum);
  };

  ele.giveconfirm2.onclick = () => {
    let giveid = ele.giveid.value;
    let givenum = ele.giveipt.value;
    closeMdl(ele.modal_give2);
    zsDq(giveid, givenum);
  };

  function zsDq(id, num) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.ZS_DQ,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        code: id,
        num: num,
      },
      success: (res) => {
        if (res.code == 1) {
          openTips(res.msg);
          toZs();
		  // getJzList();
		asyncList();
		  ele.list_today.innerHTML = '';
		  ele.list_all.innerHTML = '';
		  getBrickList(1);
		  getGoldList(1);
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  // 转赠  手续费
  function toZs() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.TO_ZS,
      method: "GET",
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.code == 1) {
          givesxf = res.data.sxf;
          ele.giveshouxu.innerHTML = "当前额外摧毁" + res.data.sxf + "%金币";
          ele.jinbi4.innerHTML = res.data.my_gold;
          openMdl(ele.modal_give);
        } else openTips(res.msg || "未知错误");
      },
    });
  }
  // 检索用户
  function searchUser(id) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.SEARCH_USER,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        code: id,
      },
      success: (res) => {
        if (res.code == 1) {
          ele.infoname.innerHTML = res.data.nick_name;
		  let age = res.data.age == null ? '0' : res.data.age
		  // ele.infosex.innerHTML = '性别：'+sex+'    年龄：'+ age; 
		  if (res.data.vip == 0) {
		  	ele.idin.style.display = 'none'
		  }else {
		  	ele.idin.innerHTML = '<img src="../img/home/zuan'+res.data.vip+'.png" alt=""><span>v'+res.data.vip+'</span>'
		  	ele.idin.style.display = 'block'
		  }
          ele.infosex.innerHTML =
            "性别：" +
            `${res.data.sex == 1 ? "男" : "女"}` +
            "    年龄：" +
            age;
          ele.infoid.innerHTML = "ID:" + res.data.invite_code;
          ele.infowx.innerHTML =
            res.data.wechat_no == null || res.data.wechat_no == ""
              ? "微信号暂未设置"
              : res.data.wechat_no;
          ele.infoqq.innerHTML =
            res.data.qq_no == null || res.data.qq_no == ""
              ? "QQ号暂未设置"
              : res.data.qq_no;
         if(res.data.qrcode == null) {
         	ele.infogroup.style.display = 'none'
         	ele.infogroup2.style.display = 'block'
         } else {
         	ele.infogroup.style.display = 'block'
         	ele.infogroup2.style.display = 'none'
         }
          ele.infotxt.innerHTML =
            res.data.introduce == null || res.data.introduce == ""
              ? "ta很懒，什么都没有介绍~"
              : res.data.introduce;
          if(res.data.head_pic == null) {
          	ele.headpic.src = res.data.sex == 1 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png' : 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png'
          }else {
          	ele.headpic.src = IMG_DOMAIN + res.data.head_pic;
          }
          let htmlcard = "";
          for (let i = 0; i < res.data.house_list.length; i++) {
            htmlcard +=
              '<div class="infoCard">' +
              '<div class="card1">' +
              '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/fcz.png" alt="">' +
              "<span>X" +
              res.data.house_list[i].zs_card_record.has_num +
              "</span>" +
              "</div>" +
              '<p class="card2">' +
              res.data.house_list[i].name +
              "</p>" +
              " </div>";
          }
          ele.cardBox.innerHTML = htmlcard;
          openMdl(ele.modal_info);
          ele.copywx.onclick = () => {
            copy(ele.infowx.innerHTML);
            if (ele.infowx.innerHTML) {
              openTips("复制成功~");
            } else {
              openTips("复制失败，请手动复制~");
            }
          };
          ele.copyqq.onclick = () => {
            copy(ele.infoqq.innerHTML);
            if (ele.infoqq.innerHTML) {
              openTips("复制成功~");
            } else {
              openTips("复制失败，请手动复制~");
            }
          };
        } else openTips(res.msg || "未知错误");
      },
    });
  }
  function initList() {
    let bai = ((obj.now_cc / obj.max_cc) * 100 || 0).toFixed(2) + "%";
    // !渲染进度条
    ele.now_cc.innerHTML = obj.now_cc;
    ele.last_cc.innerHTML = obj.max_cc;
    ele.nengliangjindu.style.width = bai;
    // !弹窗里面进度条
    ele.jindus.innerHTML = bai;
    ele.jindul.style.width = bai;
    //! 渲染房产证
    if (obj.jz_num == 0) {
      ele.juzhuzhneg.classList.add("pai2");
      ele.juzhuzhneg.onclick = () => {
        openTips("暂未获得，可以通过居住世纪城、铭门首府、南湖山庄房产获得");
      };
    } else {
      if (obj.h_id && obj.h_id == 2) {
        ele.juzhuzhneg.classList.add("pai22");
        ele.juzhuzhneg.classList.remove("pai");
        ele.juzhuzhneg.classList.remove("pai2");
      } else if (obj.h_id && obj.h_id == 3) {
        ele.juzhuzhneg.classList.add("pai33");
        ele.juzhuzhneg.classList.remove("pai");
        ele.juzhuzhneg.classList.remove("pai2");
      } else if (obj.h_id && obj.h_id == 4) {
        ele.juzhuzhneg.classList.add("pai44");
        ele.juzhuzhneg.classList.remove("pai");
        ele.juzhuzhneg.classList.remove("pai2");
      }
    }
    if (obj.zl_num == 0) {
      ele.zulouzheng.classList.add("lei2");
      ele.zulouzheng.onclick = () => {
        openTips("暂未获得，可以通过租赁世纪城房产获得");
      };
    }
    if (obj.house_num_1 == 0) {
      ele.top_t_1.classList.add("top_t22s");
      ele.top_t_1.onclick = () => {
        openTips("暂未获得，可以通购买铭门首府方式获得");
      };
    }
    if (obj.house_num_2 == 0) {
      ele.top_t_2.classList.add("top_c2");
      ele.top_t_2.onclick = () => {
        openTips("暂未获得，可以通购买南湖山庄方式获得");
      };
    }
    // 姓名
    if (obj.agent && obj.agent.detail && obj.agent.detail.head_pic) {
      ele.touxiang.src = IMG_DOMAIN + obj.agent.detail.head_pic;
    } else {
      if (obj.agent && obj.agent.detail && obj.agent.detail.sex == 1) {
        ele.touxiang.src = "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png";
      } else {
        ele.touxiang.src = "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png";
      }
    }
    if (obj.agent && obj.agent.detail) {
      ele.name_n.innerHTML = obj.agent.detail.nick_name;
    } else {
      ele.name_n.innerHTML = "天天来收租";
    }
    ele.nengliang.innerHTML = obj.my_power;
    // 渲染金币
    ele.jinbidui.innerHTML = Number(obj.agent.diamond).toFixed(2);
    ele.jinbi3.innerHTML = obj.agent.diamond;
    ele.jinbi2.innerHTML = obj.agent.diamond;
    ele.haohua.innerHTML = obj.agent.all_luxury;
    // !渲染钻
	let _data = obj.agent;
	ele.toplv.innerHTML = _data.vip == 0 ? '<p><span>ID：'+_data.invite_code+'</span></p>' : '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/zuan'+_data.vip+'.png" alt=""><p><span>V'+_data.vip+'</span></p>'
    // if (obj.agent.vip == 0) {
    //   closeMdl(ele.zuan_shi);
    //   ele.zuan.innerHTML = `<span class="id_code">ID:${obj.agent.invite_code}</span>`;
    // } else if (obj.agent.vip == 1) {
    //   ele.zuan_shi.src = "http://img.qxgs.cc/tiantianlaishouzu/img/home/zuan1.png";
    //   openMdl(ele.zuan_shi);
    //   ele.zuan.innerHTML = 'V' + obj.agent.vip;
    // } else if (obj.agent.vip == 2) {
    //   ele.zuan_shi.src = "http://img.qxgs.cc/tiantianlaishouzu/img/home/zuan2.png";
    //   openMdl(ele.zuan_shi);
    //   ele.zuan.innerHTML = 'V' + obj.agent.vip;
    // } else if (obj.agent.vip == 3) {
    //   ele.zuan_shi.src = "http://img.qxgs.cc/tiantianlaishouzu/img/home/zuan3.png";
    //   openMdl(ele.zuan_shi);
    //   ele.zuan.innerHTML = 'V' + obj.agent.vip;
    // }
    ele.nengsd.innerHTML = `能量产出：${obj.my_power_sd}/小时`;
    let newList = list
      .map((item, index) => {
        return `
          <div id="top_t" data-id="${item.id}" class="top_t${item.id}${
          item.id
        }" >
              <div class="top_t4">${item.name}<img style="display:${
          obj.h_id && obj.h_id == index + 1 ? "block" : "none"
        };" class="weizhi_img" src="http://img.qxgs.cc/tiantianlaishouzu/img/each_Fang/weizhi.png" alt=""></div>
            </div>
   
      `;
      })
      .join(" ");
    ele.ferter.innerHTML = newList;
    let top_tAll = document.querySelectorAll("#top_t");
    top_tAll.forEach((item) => {
      item.onclick = () => {
        if (item.dataset.id == 4) {
          yinHome(4);
          // return openTips("暂未开放，敬请期待！");
        } else if (item.dataset.id == 3) {
          yinHome(3);
        } else if (item.dataset.id == 1) {
			return openTips("敬请期待！");
        } else {
          // 刘欣 引导
          let ugid = guide.getUsersGuideId("userGuideId");
          if (ugid == 101) guide.hideCheap_101();
          else if (~[111, 120].indexOf(ugid)) guide.hideCentury_120();
          location.href = `../page/each_building.html?${item.dataset.id}`;
        }
      };
    });
    if (obj.house_num_1 == 0) {
      ele.top_t_1.innerHTML = ` `;
    } else {
      ele.top_t_1.innerHTML = `<span>x${obj.house_num_1}</span>`;
    }
    if (obj.house_num_1 == 1) {
      ele.top_t_2.innerHTML = ` `;
    } else {
      ele.top_t_2.innerHTML = `<span>x${obj.house_num_2}</span>`;
    }
    // 这个是渲染能量
    // ele.left_num.innerHTML = `
    // <p>我的豪华值：<span class="span_l">${obj.my_luxury}</span></p>
    // <p>能量产生总速度：<span>${obj.my_power_sd}个/小时</span></p>
    // <p>当前拥有能量数：<span>${obj.my_power}</span></p>`;
  }

  // 幸运数字---------------------------------------------------------------------------------------------------------------------------------------------------------

  // 请求幸运数字接口
  function getownnum() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.GETLUCKNUM,
      method: "GET",
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.code == 200) {
          ele.numchance.innerHTML = `竞猜机会 :${res.data.chance}`;
          ele.l_id = res.data.now_phase.id;
          ele.num_text.innerHTML = `第${res.data.now_phase.phase}期`;
          drawownnum(res);
          lick_number(res);
          drawnewMoban(res);
        } else openTips(res.msg || "未知错误");
      },
    });
  }
  // !领取能量
  function lingprow() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.LINGQUPROW,
      method: "GET",
      header: {
        Authorization: token,
      },
      success: (res) => {
        openTips(res.msg);
        asyncList();
      },
    });
  }

  // 渲染每日任务
  function lick_number(res) {
    let newArr = res.data.task_list
      .map((item, index) => {
        let img =
          item.state == 1
            ? '<img class="son_right_img" src="http://img.qxgs.cc/tiantianlaishouzu/img/number/gou.png" alt="">'
            : "";
        return `<div class="son_right_left">
						<p>${index + 1}.${item.describe}(${item.record_num}/${item.num})</p >
						${img}
					</div>`;
      })
      .join(" ");
    ele.task_num.innerHTML = newArr;
  }

  // 渲染昨日幸运数字
  function drawownnum(res) {
    if (res.data.last_res != "") {
      let html = res.data.last_res.lucky_num
        .map((item, index) => {
          return `<div class="son_right_img">
							<span>${item}</span>
						</div>`;
        })
        .join("");
      ele.son_num.innerHTML = html;
    }
  }

  let luckobj = [
    {
      title: "第一组",
      arr: ["", "", "", "", ""],
    },
    {
      title: "第二组",
      arr: ["", "", "", "", ""],
    },
    {
      title: "第三组",
      arr: ["", "", "", "", ""],
    },
    {
      title: "第四组",
      arr: ["", "", "", "", ""],
    },
    {
      title: "第五组",
      arr: ["", "", "", "", ""],
    },
  ];

  ele.zuhao = $("#zuhao");

  // 渲染我已经提交的数据
  function drawnewMoban(res) {
    for (let i = 0; i < res.data.user_lucky_nums.length; i++) {
      luckobj[i].arr = res.data.user_lucky_nums[i].chose_num;
    }
    // console.log(luckobj);
    let numArr = luckobj
      .map((item) => {
        return `
						<div class="son_bottom">
							<div class="son_left">
								<p>${item.title}</p>
							</div>
							<div class="son_right">
								<div class="son_right_img">
									<span>${item.arr[0]}</span>
								</div>
								<div class="son_right_img">
									<span>${item.arr[1]}</span>
								</div>
								<div class="son_right_img">
									<span>${item.arr[2]}</span>
								</div>
								<div class="son_right_img">
									<span>${item.arr[3]}</span>
								</div>
								<div class="son_right_img">
									<span>${item.arr[4]}</span>
								</div>
							</div>
						</div>`;
      })
      .join("");
    ele.zuhao.innerHTML = numArr;
  }
  //! 能量记录调用接口------------------------------------
  function nnegliangjl() {
    let token = getCookie("token");
    ajax({
      method: "post",
      url: API_PATH.PROWRECOL,
      header: {
        Authorization: token,
      },
      data: {
        page: page,
        // size: 1,
      },
      success: (res) => {
        if (res.code == 1) {
          obj = res.data.detail;
          prowList = [...prowList, ...res.data.data];
          if (prowList.length === 0) {
            page = 0;
            ele.more4.style.display = "none";
            ele.empty4.style.display = "block";
          } else {
            initQgjl();
            page++;
            if (page > res.data.last_page) {
              ele.more4.innerText = "没有更多了";
              ele.more4.onclick = null;
            } else {
              ele.more4.innerText = "加载更多";
              ele.more4.onclick = () => nnegliangjl(page);
            }
          }
        } else openTips(res.msg);
        initQgjl();
      },

      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !判断能不能进去
  function yinHome(ids) {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.HOMEDETAIL,
      header: {
        Authorization: token,
      },
      data: {
        id: ids,
      },
      success: (res) => {
        if (res.code != 1) {
          openTips(res.msg);
        }
        if (res.code == 1) {
          location.href = `../page/each_building.html?${ids}`;
        }
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !渲染切割记录
  function initQgjl() {
    let newqgjlList = prowList
      .map((item) => {
        return `
       <div class="navlist">
                  <p>${item.remark}</p>
                  <span>${item.created_at}</span>
                  <div style="display:${
                    item.type != 0 ? "block" : "none"
                  };" class="">
                         <img style="width:30px;heiht:30px;" src="${
                           item.house_info && item.house_info.logo
                             ? IMG_DOMAIN + item.house_info.logo
                             : "http://img.qxgs.cc/tiantianlaishouzu/img/yuanshi/MG_NL.png"
                         }" alt="" />
                         </span><span>x${Number(item.money).toFixed(0)}</span>
                  </div>
                  <div style="display:${
                    item.type == 0 ? "block" : "none"
                  };" class="">
                    <img src="http://img.qxgs.cc/tiantianlaishouzu/img/yuanshi/MG_NL.png" alt="" />
                    <span>${item.money}</span>
                  </div>
                </div>
      `;
      })
      .join(" ");
    ele.navcont_List.innerHTML = newqgjlList;
  }
  let idi = []; //用来保存选择的数据
  let arr = [
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
    22, 23, 24, 25, 26, 27, 28, 29, 30,
  ];
  const newArr = arr
    .map((item) => {
      return `<div class="num_sonnum">${item}</div>`;
    })
    .join("");
  // 循环下面的数字
  ele.num_select.innerHTML = newArr;
  let yuer = document.querySelectorAll(".num_sonnum");

  for (let i = 0; i < yuer.length; i++) {
    yuer[i].onclick = (e) => {
      // console.log(idi);
      // console.log(e, 4444);
      // 判断点击相同的元素删除
      for (let i = 0; i < idi.length; i++) {
        if (e.target.innerHTML == Number(idi[i])) {
          idi.splice(i, 1);
          e.target.classList.remove("quanquan");
          // console.log(idi);
          return;
        }
      }
      if (e.target.className == "quanquan") {
        return;
      }
      if (idi.length >= 5) {
        return;
      }
      idi.push(Number(e.target.innerHTML));
      // console.log(idi);
      // 添加节点
      yuer[i].classList.add("quanquan");
    };
  }

  // 获取所有背景节点
  // 删除类名方法
  function cleatName(arr) {
    // console.log(arr, 555555);
    arr.forEach((item) => {
      item.classList.remove("quanquan");
    });
  }

  // 点击提交
  ele.center_tijiao.onclick = () => {
    //是否选满选满则弹窗
    console.log(luckobj[4].arr[4]);
    if (luckobj[4].arr[4] == "") {
      ele.quanquan = document.querySelectorAll(".quanquan");
      if (idi.length != 5) {
        openTips("请选择完整号码");
      } else {
        openMdl(ele.modal_submitTo);
      }
    } else {
      openTips("您已全部选择,请提交后再来");
    }
  };

  // 点击随机选择
  ele.center_suiji = $("#center_suiji");
  ele.center_suiji.onclick = () => {
    ele.quanquan = document.querySelectorAll(".quanquan");
    cleatName(ele.quanquan);
    if (luckobj[4].arr[4] != "") {
      openTips("您已全部选择,请提交后再来");
      return;
    }
    idi = [];
    let yuer = document.querySelectorAll(".num_sonnum");
    for (let i = 0; i < 5; i++) {
      idi[i] = Math.floor(Math.random() * 30) + 1; //范围是[1~10]
      for (let j = 0; j < i; j++) {
        if (idi[i] == idi[j]) {
          i--;
        }
      }
    }
    for (let j = 0; j < idi.length; j++) {
      yuer[idi[j] - 1].classList.add("quanquan");
    }
    // console.log(idi);
  };
  // 点击中奖记录
  ele.winning_record.onclick = () => {
    location.href = "../page/winningRecord.html";
  };

  // 点击确认提交后
  ele.num_detlt_submit.onclick = () => {
    // 这里发送请求
    submitmnum(idi);
  };

  // 提交选择的数据
  function submitmnum(_data) {
    let chose_num = _data.join(",");
    let token = getCookie("token");
    // console.log(chose_num);
    ajax({
      url: API_PATH.CHOSE_NUM,
      method: "POST",
      header: {
        Authorization: token,
      },
      data: {
        chose_num: chose_num,
        l_id: ele.l_id,
      },
      success: (res) => {
        if (res.code == 200) {
          idi = [];
          closeMdl(ele.modal_submitTo);
          getownnum();
          openTips(res.message);
          cleatName(ele.quanquan);
        } else {
          openTips(res.message || "未知错误");
        }
      },
    });
  }

  // 幸运数字活动倒计时
  var countdownjs;
  countdown();
  function countdown() {
    clearInterval(countdownjs);
    var now = new Date();
    var midnight = new Date();
    midnight.setHours(24, 0, 0, 0); // 设置为今天的午夜时间
    var diff = midnight - now; // 计算距离午夜的毫秒数
    var hours = Math.floor(diff / (1000 * 60 * 60)); // 计算小时数
    var minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); // 计算分钟数
    var seconds = Math.floor((diff % (1000 * 60)) / 1000); // 计算秒数
    var countdownStr = hours + ":" + minutes + ":" + seconds;
    ele.djstext.innerHTML = countdownStr;
    countdownjs = setInterval(() => {
      countdown();
    }, 1000);
  }
})();
